package com.woniuxy.tfss.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.tfss.entity.Discount;
import com.woniuxy.tfss.entity.DiscountVO;
import com.woniuxy.tfss.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;


@Mapper
public interface UserMapper extends BaseMapper<User> {
    @Select("select * from tfss_user where phonenum=#{phoneNum}")
    public User getUserByPhoneNum(String phoneNum);

    @Select("select d.* from tfss_ud ud,tfss_discount d where ud.userid=#{userId} and ud.discountid=d.id")
    public List<Discount> getDiscountsByUserId(Integer userId);

    @Insert("insert into tfss_ud(userid,discountid,time) values(#{userId},#{discountId},#{time})")
    public void addDiscount (Integer userId,Integer discountId,String time);

    @Delete("DELETE FROM tfss_ud WHERE userid=#{userId} and discountid=#{discountId} ORDER BY TIME DESC LIMIT 1")
    public void reduceDiscount(Integer userId,Integer discountId);

   @Select("SELECT ud.time, ud.userid, dis.* from tfss_ud ud, tfss_discount dis WHERE ud.userid = #{userId} and ud.discountid = dis.id")
   public List<DiscountVO> getDiscountVoByUserId(Integer userId);

   @Update("update tfss_user set password = #{password} where phonenum = #{phoneNum}")
   public void changePwdByPhoneNum(String phoneNum, String password);

}
